﻿using AutoMapper;
using MediatR;
using WMS.API.Application.Command.DeliveryOrderManagement.DeliveryOrder;
using WMS.Domain.Entities.DeliveryOrderManagement;
using WMS.ErrorCode;
using WMS.Interfactructure.Interfaces;

namespace WMS.API.Application.CommandHandlers.DeliveryOrderManagement.DeliveryOrder
{

    /// <summary>
    /// 修改待发货订单
    /// </summary>
    public class UpddatePendingFreightCommandHandler : IRequestHandler<UpddatePendingFreightCommand, APIResult<int>>
    {
        private readonly IBaseRepository<PendingFreightModel> _pendingrepository;
        private readonly IMapper mapper;

        /// <summary>
        /// 修改待发货订单
        /// </summary>
        /// <param name="pendingrepository"></param>
        /// <param name="mapper"></param>
        public UpddatePendingFreightCommandHandler(IBaseRepository<PendingFreightModel> pendingrepository,IMapper mapper)
        {
            this._pendingrepository = pendingrepository;
            this.mapper = mapper;
        }
        public async Task<APIResult<int>> Handle(UpddatePendingFreightCommand request, CancellationToken cancellationToken)
        {
            APIResult<int> result = new APIResult<int>("修改待发货订单成功");
            result.Message = "更新待发货订单成功";
            result.Code = ResultCode.Success;
            PendingFreightModel pendingFreightModel=mapper.Map<PendingFreightModel>(result);

            await _pendingrepository.UpdateAsync(pendingFreightModel);
            return await Task.FromResult(result);
        }
    }
}
